﻿using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;


namespace Gpf.Whs.YouTubeDownloader.Service
{
    [RunInstaller(true)]
    public partial class YouTubeServiceInstaller : Installer
    {
        private readonly ServiceProcessInstaller _serviceProcessInstaller1;
        private readonly ServiceInstaller _serviceInstaller1;

        public YouTubeServiceInstaller()
        {
            InitializeComponent();

            _serviceProcessInstaller1 = new ServiceProcessInstaller
            {
                Account = ServiceAccount.LocalSystem,
                Password = null,
                Username = null
            };

            _serviceInstaller1 = new ServiceInstaller();
            _serviceInstaller1.ServiceName = "WhsYouTubeDownloader";
            _serviceInstaller1.StartType = ServiceStartMode.Automatic;

            Installers.AddRange(new Installer[] { _serviceProcessInstaller1, _serviceInstaller1 });
        }

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            var c = new ServiceController("WhsYouTubeDownloader");
            c.Start();
            c.Close();
        }

    }
}
